﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.ui.renderers {
    import reprise.ui.*;
    import reprise.events.*;
    import flash.display.*;
    import flash.geom.*;
    import reprise.controls.*;
    import reprise.css.propertyparsers.*;

    public class AbstractTooltip extends UIComponent {

        protected var m_mousedComponent:UIComponent;
        protected var m_mousedElement:DisplayObject;
        protected var m_label:Label;
        protected var m_tooltipDataProvider:Object;

        public static var className:String = "AbstractTooltip";

        override protected function validateAfterChildren():void{
            super.validateAfterChildren();
            applyOutOfFlowChildPositions();
        }
        override public function remove(... _args):void{
            ((m_mousedComponent) && (m_mousedComponent.removeEventListener(DisplayEvent.VALIDATION_COMPLETE, mousedEvent_validationComplete)));
            super.remove(_args);
        }
        override protected function initDefaultStyles():void{
            super.initDefaultStyles();
            m_elementDefaultStyles.setStyle("position", "static");
            m_elementDefaultStyles.setStyle("top", "18");
            m_elementDefaultStyles.setStyle("left", "0");
        }
        protected function positionRelativeToMouse():Point{
            var _local1:Point = new Point();
            _local1.x = (m_mousedElement.stage.mouseX + style.left);
            _local1.y = (m_mousedElement.stage.mouseY + style.top);
            return (_local1);
        }
        public function updatePosition():void{
            var _local1:Point;
            switch (style.position){
                case DisplayPosition.POSITION_ABSOLUTE:
                    if (!m_mousedComponent){
                        return;
                    };
                    _local1 = positionRelativeToElement(m_mousedComponent);
                    break;
                case DisplayPosition.POSITION_FIXED:
                    _local1 = positionRelativeToElement(stage);
                    break;
                case DisplayPosition.POSITION_STATIC:
                    if (!((m_mousedElement) && (m_mousedElement.stage))){
                        return;
                    };
                    _local1 = positionRelativeToMouse();
                    break;
            };
            setPosition(_local1.x, _local1.y);
        }
        override protected function resolveContainingBlock():void{
            m_containingBlock = m_rootElement;
        }
        override protected function createChildren():void{
            m_label = Label(addChild(new Label()));
            m_label.cssClasses = "tooltipLabel";
        }
        public function setTooltipDataProvider(_arg1:Object):void{
            m_tooltipDataProvider = _arg1;
        }
        public function mousedElement():DisplayObject{
            return (m_mousedElement);
        }
        public function tooltipDataProvider():Object{
            return (m_tooltipDataProvider);
        }
        override protected function refreshSelectorPath():void{
            var _local2:Array;
            var _local1:String = ((m_selectorPath) || (""));
            super.refreshSelectorPath();
            if ((m_mousedComponent is UIComponent)){
                m_selectorPath = ((UIComponent(m_mousedComponent).selectorPath + " ") + m_selectorPath.split(" ").pop());
            } else {
                _local2 = _local1.split(" ");
                _local2.pop();
                _local2.push(m_selectorPath.split(" ").pop());
                m_selectorPath = _local2.join(" ");
            };
            if (m_selectorPath != _local1){
                m_selectorPathChanged = true;
                return;
            };
            m_selectorPathChanged = false;
        }
        override protected function resolvePositioningProperties():void{
            m_positionInFlow = 0;
        }
        public function setMousedComponent(_arg1:UIComponent):void{
            ((m_mousedComponent) && (m_mousedComponent.removeEventListener(DisplayEvent.VALIDATION_COMPLETE, mousedEvent_validationComplete)));
            m_mousedComponent = _arg1;
            ((m_mousedComponent) && (m_mousedComponent.addEventListener(DisplayEvent.VALIDATION_COMPLETE, mousedEvent_validationComplete)));
            validateElement(true, true);
            updatePosition();
        }
        public function mousedComponent():UIComponent{
            return (m_mousedComponent);
        }
        public function data():Object{
            return (m_tooltipData);
        }
        public function setPosition(_arg1:Number, _arg2:Number):void{
            var _local3:Point = new Point(_arg1, _arg2);
            _local3 = stage.localToGlobal(_local3);
            _local3.y = Math.max(-(m_currentStyles.marginTop), (_local3.y + m_currentStyles.marginTop));
            _local3.y = Math.min(((stage.stageHeight - outerHeight) - m_currentStyles.marginTop), _local3.y);
            _local3.x = Math.max(-(m_currentStyles.marginLeft), (_local3.x + m_currentStyles.marginLeft));
            _local3.x = Math.min(((stage.stageWidth - outerWidth) - m_currentStyles.marginLeft), _local3.x);
            _local3 = parent.globalToLocal(_local3);
            x = _local3.x;
            y = _local3.y;
        }
        public function setData(_arg1:Object):void{
            m_tooltipData = _arg1;
            m_label.setLabel(String(_arg1));
        }
        protected function mousedEvent_validationComplete(_arg1:DisplayEvent):void{
            m_mousedComponent.document.addEventListener(DisplayEvent.DOCUMENT_VALIDATION_COMPLETE, document_validationComplete);
        }
        protected function document_validationComplete(_arg1:DisplayEvent):void{
            m_mousedComponent.document.removeEventListener(DisplayEvent.DOCUMENT_VALIDATION_COMPLETE, document_validationComplete);
            validateElement(true, true);
            updatePosition();
        }
        protected function positionRelativeToElement(_arg1:DisplayObject):Point{
            var _local2:Point = new Point();
            if (((style.right) && (!(style.left)))){
                _local2.x = ((_arg1.width - style.right) - width);
            } else {
                _local2.x = style.left;
            };
            if (((style.bottom) && (!(style.top)))){
                _local2.y = ((_arg1.height - style.bottom) - height);
            } else {
                _local2.y = style.top;
            };
            return (_arg1.localToGlobal(_local2));
        }
        public function setMousedElement(_arg1:DisplayObject):void{
            m_mousedElement = _arg1;
        }

    }
}//package reprise.ui.renderers 
